package com.niiwoo.civet.trade.service.local.kaola.newrepay;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.fastjson.JSONObject;
import com.dangdang.ddframe.rdb.sharding.api.HintManager;
import com.dangdang.ddframe.rdb.sharding.hint.HintManagerHolder;
import com.lycheepay.gateway.client.dto.QueryTradeRecordDTO;
import com.lycheepay.gateway.client.dto.QueryTradeRecordResultDTO;
import com.niiwoo.civet.account.dto.common.sendmessage.RepaymentSuccessDTO;
import com.niiwoo.civet.account.enums.RepaymentTypeLetterEnum;
import com.niiwoo.civet.account.service.MessageSendDubboService;
import com.niiwoo.civet.trade.constant.RabbitConstant;
import com.niiwoo.civet.trade.dao.entity.*;
import com.niiwoo.civet.trade.dao.mapper.*;
import com.niiwoo.civet.trade.dto.FollowWorkTaskRepaymentDTO;
import com.niiwoo.civet.trade.dto.ProjectBorrowerAmountSumDTO;
import com.niiwoo.civet.trade.dto.ProjectBorrowerPlanNewDTO;
import com.niiwoo.civet.trade.dto.common.RefundCallBackForAccountDTO;
import com.niiwoo.civet.trade.dto.kaola.Result;
import com.niiwoo.civet.trade.enums.ProjectPlanStatusEnum;
import com.niiwoo.civet.trade.enums.kaola.KaoLaRepayOrderRepayTypeEnum;
import com.niiwoo.civet.trade.enums.kaola.KaolaRepayOrderRepayStatusEnum;
import com.niiwoo.civet.trade.enums.kaola.QueryTradeRecordResultStatusEnum;
import com.niiwoo.civet.trade.property.LycheePayProperties;
import com.niiwoo.civet.trade.service.local.kaola.LycheePayRequestService;
import com.niiwoo.civet.trade.service.local.newRefund.common.RefundCommonService;
import com.niiwoo.civet.trade.service.local.newRefund.notify.RefundNotifyFacade;
import com.niiwoo.civet.trade.utils.RepaymentUtil;
import com.niiwoo.tripod.base.utils.DateUtils;
import com.niiwoo.tripod.tiancheng.component.TianChengRefundEventService;
import com.niiwoo.tripod.tiancheng.request.df.ProjectRefundEventRequest;
import com.niiwoo.tripod.tiancheng.request.df.ProjectRefundEventRequestDetail;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import static com.alibaba.fastjson.JSON.toJSONString;

/**
 * 考拉理财申请借款接口（快付通）
 *
 * @author daizhiyue
 * @dateTime 2018-01-01
 */
@Service
@Slf4j
public class KaoLaLiCaiApplyForKFTService {


    @Autowired
    private ProjectMapperExt projectMapperExt;

    @Autowired
    private ProjectBorrowerSummaryMapperExt projectBorrowerSummaryMapperExt;

    @Autowired
    private KaoLaLiCaiRepayCallbackForKFTService kaoLaLiCaiRepayCallbackForKFTService;

    @Autowired
    private KaolaRepayOrderMapperExt kaolaRepayOrderMapperExt;

    @Autowired
    private KaolaWithholdOrderMapperExt kaolaWithholdOrderMapperExt;

    @Autowired
    private LycheePayRequestService lycheePayRequestService;

    @Reference(version = "1.0.0")
    private MessageSendDubboService messageSendDubboService;


    @Autowired
    private LycheePayProperties lycheePayProperties;


    @Autowired
    private RefundNotifyFacade refundNotifyFacade;


    @Autowired
    private RabbitTemplate rabbitTemplate;


    @Autowired
    private ProjectBorrowerPlanNewMapperExt projectBorrowerPlanNewMapperExt;

    @Reference(version = "1.0.0")
    private TianChengRefundEventService tianChengRefundEventService;


    @Autowired
    private RefundCommonService refundCommonService;

    /**
     * 考拉理财还款后处理
     *
     * @param kaolaWithholdOrder
     * @return
     */
    public Result notifyRepayment(KaolaWithholdOrder kaolaWithholdOrder) {
        Result result = new Result(Result.SUCCESS_RET);
        // 判断还款结果
        if (kaolaWithholdOrder == null || null == kaolaWithholdOrder.getReqNo()
                || null == kaolaWithholdOrder.getRepayOrderId()) {
            log.info("考拉理财标还款状态--请求编号或还款订单id为空!");
            result.setFailureMessage("考拉理财标还款状态--请求编号或还款订单id为空!");
            return result;
        }

        QueryTradeRecordDTO dtoForQueryTradeRecord = new QueryTradeRecordDTO();
        QueryTradeRecordResultDTO resultTradeRecord = null;
        List<QueryTradeRecordDTO.Criteria> criterias = new ArrayList<QueryTradeRecordDTO.Criteria>();
        criterias.add(dtoForQueryTradeRecord.new Criteria(lycheePayProperties.getProductNo().getGbpCollect(), "", kaolaWithholdOrder.getOrderNo()));
        try {
            resultTradeRecord = lycheePayRequestService.queryTradeRecord(criterias);
        } catch (Exception e) {
            log.error("考拉理财标查询交易结果异常:{}", e);
        }
        log.info("考拉理财标查询交易结果:{}" + JSONObject.toJSONString(resultTradeRecord));

        if (resultTradeRecord == null || resultTradeRecord.getDetails().get(0) == null || resultTradeRecord.getDetails().get(0).getStatus() == null) {
            log.info("考拉理财标快付通查询结果查询结果为空!");
            result.setFailureMessage("考拉理财标快付通查询结果查询结果为空!");
            return result;
        }
        return notifyRepayment(kaolaWithholdOrder, resultTradeRecord);
    }


    /**
     * 考拉理财还款回调
     *
     * @param kaolaWithholdOrder
     * @param resultTradeRecord
     * @return
     */
    public Result notifyRepayment(KaolaWithholdOrder kaolaWithholdOrder, QueryTradeRecordResultDTO resultTradeRecord) {
        Result result = new Result(Result.SUCCESS_RET);
        try {
            KaolaRepayOrderRepayStatusEnum kaolaRepayOrderRepayStatusEmun = KaolaRepayOrderRepayStatusEnum.WITH_HOLDING;
            if (QueryTradeRecordResultStatusEnum.SUCCESS.getCode().equals(resultTradeRecord.getDetails().get(0).getStatus())) {
                //交易成功
                kaolaRepayOrderRepayStatusEmun = KaolaRepayOrderRepayStatusEnum.REPAY_SUCCESS;
            } else if (QueryTradeRecordResultStatusEnum.FAIL.getCode().equals(resultTradeRecord.getDetails().get(0).getStatus())) {
                //交易失败
                kaolaRepayOrderRepayStatusEmun = KaolaRepayOrderRepayStatusEnum.REPAY_FAIL;
            }
            masterRouteOnly();
            KaolaRepayOrder kaolaRepayOrder = kaolaRepayOrderMapperExt.selectByPrimaryKey(kaolaWithholdOrder.getRepayOrderId());
            if (kaolaRepayOrder == null) {
                log.info("考拉理财还款订单为空!");
                result.setFailureMessage("考拉理财还款订单为空!");
                return result;
            }
            // 查询项目表信息
            this.masterRouteOnly();
            ProjectBorrowerSummary summary = projectBorrowerSummaryMapperExt.selectByPrimaryKeyForUpdate(kaolaRepayOrder.getProjectId());

            RefundCallBackForAccountDTO dtoForRefundCallBackForAccount = new RefundCallBackForAccountDTO();
            dtoForRefundCallBackForAccount.setProjectId(summary.getProjectId());
            dtoForRefundCallBackForAccount.setCurrentPeriod(kaolaRepayOrder.getRepayNo());
            dtoForRefundCallBackForAccount.setBorrowerUserId(summary.getBorrowerUserId());

            // 更新考拉还款记录
            updateKaolaRepayOrder(kaolaRepayOrder, kaolaWithholdOrder, kaolaRepayOrderRepayStatusEmun, resultTradeRecord);

            RepaymentTypeLetterEnum repaymentTypeLetterEnum = summary.getCurrentPeriod().equals(summary.getTotalPeriod()) ? RepaymentTypeLetterEnum.REPAYMENT_SUCCESS_COMPLETE : RepaymentTypeLetterEnum.REPAYMENT_SUCCESS;

            // 还款回调状态成功，更改你我金融还款计划
            if (kaolaRepayOrderRepayStatusEmun.equals(KaolaRepayOrderRepayStatusEnum.REPAY_SUCCESS)) {
                if (KaoLaRepayOrderRepayTypeEnum.REPAY_NOMAL.getValue().equals(kaolaRepayOrder.getRepayType())) {
                    //考拉理财正常还款回调
                    result = kaoLaLiCaiRepayCallbackForKFTService.nomalRepayCallback(kaolaRepayOrder, kaolaWithholdOrder);
                } else if (KaoLaRepayOrderRepayTypeEnum.REPAY_SETTLE.getValue().equals(kaolaRepayOrder.getRepayType())) {
                    //提前还款
                    result = kaoLaLiCaiRepayCallbackForKFTService.settleRepayCallback(kaolaRepayOrder, kaolaWithholdOrder);
                    repaymentTypeLetterEnum = RepaymentTypeLetterEnum.REPAYMENT_SUCCESS_ADVANCE;
                } else if (KaoLaRepayOrderRepayTypeEnum.REPAY_OVERDUE.getValue().equals(kaolaRepayOrder.getRepayType())) {
                    //逾期还款
                    result = kaoLaLiCaiRepayCallbackForKFTService.overDueCallback(kaolaRepayOrder, kaolaWithholdOrder);
                } else if (KaoLaRepayOrderRepayTypeEnum.REPAY_BADLOANS.getValue().equals(kaolaRepayOrder.getRepayType())) {
                    //严重逾期还款(严重逾期还全部)
                    result = kaoLaLiCaiRepayCallbackForKFTService.settleBadDebtDue(kaolaRepayOrder, kaolaWithholdOrder);
                    //坏账还款-结清(第二次将坏账那期之后的所有结清））
                    repaymentTypeLetterEnum = RepaymentTypeLetterEnum.REPAYMENT_SUCCESS_COMPLETE;

                }

                if (result.isSuccess()) {
                    if (repaymentTypeLetterEnum != null) {
                        repaymentSuccessPushLetterToBorrowerAsyn(summary, repaymentTypeLetterEnum, kaolaRepayOrder);
                    }
                    sendTianCheng(dtoForRefundCallBackForAccount);
                    //通知app
                    sendMqMsgToApp(dtoForRefundCallBackForAccount);

                    //清偿债权
                    kaoLaLiCaiRepayCallbackForKFTService.updateCreditorStatus2Settlement(kaolaRepayOrder);
                }
            } else if (kaolaRepayOrderRepayStatusEmun.equals(KaolaRepayOrderRepayStatusEnum.REPAY_FAIL)) {
                // 正常还款/逾期还款/提前结清失败才发消息
                result = kaoLaLiCaiRepayCallbackForKFTService.sendRepaymentFailMessage(kaolaRepayOrder, resultTradeRecord);

            }
        } catch (Exception e) {
            log.error("考拉还款回调处理异常!reqNo：" + kaolaWithholdOrder.getReqNo(), e);
            result.setFailureMessage("考拉理财还款回调处理异常");
        }

        return result;
    }


    /**
     * 获取自身代理
     *
     * @return
     */
    private KaoLaLiCaiApplyForKFTService getSelfProxy() {
        return (KaoLaLiCaiApplyForKFTService) AopContext.currentProxy();
    }


    /**
     * 更新还款订单记录
     *
     * @param kaolaRepayOrder
     * @param kaolaWithholdOrder
     * @param kaolaRepayOrderRepayStatusEmun
     * @param resultTradeRecord
     */
    private void updateKaolaRepayOrder(KaolaRepayOrder kaolaRepayOrder, KaolaWithholdOrder kaolaWithholdOrder, KaolaRepayOrderRepayStatusEnum kaolaRepayOrderRepayStatusEmun, QueryTradeRecordResultDTO resultTradeRecord) {
        KaolaRepayOrder kaolaRepayOrderForUpdate = new KaolaRepayOrder();
        KaolaWithholdOrder kaolaWithholdOrderForUpdate = new KaolaWithholdOrder();
        kaolaWithholdOrderForUpdate.setId(kaolaWithholdOrder.getId());
        kaolaWithholdOrderForUpdate.setStatus(Byte.parseByte(resultTradeRecord.getDetails().get(0).getStatus()));
        String bankReturnTime = resultTradeRecord.getDetails().get(0).getBankReturnTime();
        kaolaWithholdOrderForUpdate.setBankReturnTime(Optional.ofNullable(bankReturnTime).map(r -> DateUtils.parseDateFromString(r, DateUtils.DATETIME_FORMAT)).orElse(null));
        kaolaWithholdOrderForUpdate.setFailureDetails(resultTradeRecord.getDetails().get(0).getFailureDetails());
        kaolaWithholdOrderForUpdate.setErrorCode(resultTradeRecord.getDetails().get(0).getErrorCode());

        kaolaRepayOrderForUpdate.setId(kaolaRepayOrder.getId());
        kaolaRepayOrderForUpdate.setRepayStatus(kaolaRepayOrderRepayStatusEmun.getValue());

        kaolaRepayOrderMapperExt.updateByPrimaryKeySelective(kaolaRepayOrderForUpdate);
        kaolaWithholdOrderMapperExt.updateByPrimaryKeySelective(kaolaWithholdOrderForUpdate);
    }


    /**
     * 还款成功发送消息给借款人
     *
     * @param projectBorrowerSummary
     * @param repaymentTypeLetterEnum
     * @param kaolaRepayOrder
     */
    private void repaymentSuccessPushLetterToBorrowerAsyn(ProjectBorrowerSummary projectBorrowerSummary, RepaymentTypeLetterEnum repaymentTypeLetterEnum, KaolaRepayOrder kaolaRepayOrder) {
        log.info("repaymentSuccessPushLetterToBorrowerAsyn.projectBorrowerSummary={}", toJSONString(projectBorrowerSummary));
        try {
            CompletableFuture.runAsync(() -> this.repaymentSuccessPushLetterToBorrower(projectBorrowerSummary, repaymentTypeLetterEnum, kaolaRepayOrder));
        } catch (Exception e) {
            log.error("repaymentSuccessPushLetterToBorrowerAsyn异常，projectBorrowerSummary={}", toJSONString(projectBorrowerSummary), e);
        }
    }


    /**
     * 还款成功发送消息给借款人
     *
     * @param projectBorrowerSummary
     * @param repaymentTypeLetterEnum
     * @param kaolaRepayOrder
     */
    public void repaymentSuccessPushLetterToBorrower(ProjectBorrowerSummary projectBorrowerSummary, RepaymentTypeLetterEnum repaymentTypeLetterEnum, KaolaRepayOrder kaolaRepayOrder) {
        Long projectId = projectBorrowerSummary.getProjectId();
        Integer currentPeriod = projectBorrowerSummary.getCurrentPeriod();
        Integer totalPeriod = projectBorrowerSummary.getTotalPeriod();

        RepaymentSuccessDTO repaymentSuccessDTO = new RepaymentSuccessDTO();
        repaymentSuccessDTO.setUserId(projectBorrowerSummary.getBorrowerUserId());
        repaymentSuccessDTO.setProjectId(projectId);
        repaymentSuccessDTO.setProjectTitle(projectBorrowerSummary.getProjectTitle());
        repaymentSuccessDTO.setCurrentPeriod(currentPeriod);
        repaymentSuccessDTO.setTotalPeriods(totalPeriod);
        repaymentSuccessDTO.setRepaymentTypeLetterEnum(repaymentTypeLetterEnum);
        repaymentSuccessDTO.setSuccessRepaymentAmount(kaolaRepayOrder.getRepayAmount());
        messageSendDubboService.sendLetterForRepaymentFromKaola(repaymentSuccessDTO);
    }


    public void sendMqMsgToApp(RefundCallBackForAccountDTO dto) {
        try {
            Project project = projectMapperExt.selectByPrimaryKey(dto.getProjectId());
            log.info("考拉理财还款回调--app通知发送,projectId={}", project.getProjectId());
            ProjectBorrowerPlanNew projectBorrowerPlanNew = projectBorrowerPlanNewMapperExt.selectByProjectAndPeriod(dto.getProjectId(), dto.getCurrentPeriod());
            ProjectBorrowerPlanNewDTO projectBorrowerAmountSumDTO = projectBorrowerPlanNewMapperExt.selectByProjectIdAndPeroidForAmount(dto.getProjectId(), dto.getCurrentPeriod());
            FollowWorkTaskRepaymentDTO followWorkTaskRepaymentDTO = new FollowWorkTaskRepaymentDTO();
            followWorkTaskRepaymentDTO.setBorrowerPlanId(projectBorrowerPlanNew.getId());
            followWorkTaskRepaymentDTO.setOverState(projectBorrowerPlanNew.getStatus());
            followWorkTaskRepaymentDTO.setRepaymentAmount(projectBorrowerAmountSumDTO.getCapital().add(projectBorrowerAmountSumDTO.getInterest()).add(projectBorrowerAmountSumDTO.getPenaltyFee())
                    .add(projectBorrowerAmountSumDTO.getManagementFee()).add(projectBorrowerAmountSumDTO.getGuaranteeFee()));
            followWorkTaskRepaymentDTO.setRepaymentDate(projectBorrowerAmountSumDTO.getOverDate());
            rabbitTemplate.convertAndSend(RabbitConstant.Exchange.FOLLOW_WORK_TASK_REPAYMENT, RabbitConstant.RoutingKey.FOLLOW_WORK_TASK_REPAYMENT,
                    followWorkTaskRepaymentDTO);
        } catch (Exception e) {
            log.error("send to app followWorkTaskRepayment failed.", e);
        }
    }


    /**
     * 还款成功天秤回流
     *
     * @param dto
     */
    public void sendTianCheng(RefundCallBackForAccountDTO dto) {
        try {
            // 查询标的还款计划
            List<ProjectBorrowerPlanNewDTO> projectBorrowerPlanNewDTOList = refundCommonService
                    .getProjectBorrowerPlanNewList(dto.getProjectId(), dto.getBorrowerUserId());

            List<ProjectRefundEventRequestDetail> projectRefundEventRequestDetailList = Lists.newArrayList();

            ProjectBorrowerAmountSumDTO projectBorrowerAmountSumDTO = new ProjectBorrowerAmountSumDTO();

            // 遍历还款计划生成详情数据，同时累加标的相关金额信息
            projectBorrowerPlanNewDTOList.forEach(projectBorrowerPlanNewDTO -> {
                ProjectRefundEventRequestDetail projectRefundEventRequestDetail = new ProjectRefundEventRequestDetail();
                projectRefundEventRequestDetail.setProjectId(projectBorrowerPlanNewDTO.getProjectId());
                projectRefundEventRequestDetail.setUserId(projectBorrowerPlanNewDTO.getUserId());
                projectRefundEventRequestDetail.setCurrentPeriods(projectBorrowerPlanNewDTO.getPeriod());
                projectRefundEventRequestDetail.setTotalPeriods(projectBorrowerPlanNewDTO.getTotalPeriod());
                projectRefundEventRequestDetail.setRealCostAmount(projectBorrowerPlanNewDTO.getRefundedCapital());
                projectRefundEventRequestDetail.setRealRefundInterest(projectBorrowerPlanNewDTO.getRefundedInterest());
                projectRefundEventRequestDetail.setOverdueFine(projectBorrowerPlanNewDTO.getPenaltyFee());
                projectRefundEventRequestDetail.setStatus(ProjectPlanStatusEnum.enumOf(projectBorrowerPlanNewDTO.getStatus()).getTianchengStatus());
                projectRefundEventRequestDetail.setUpdateTime(projectBorrowerPlanNewDTO.getUpdateTime().getTime());

                // 结清时间
                if (projectBorrowerPlanNewDTO.getOverDate() != null) {
                    projectRefundEventRequestDetail.setRealRefundDate(projectBorrowerPlanNewDTO.getOverDate().getTime());
                } else {
                    projectRefundEventRequestDetail.setRealRefundDate(projectBorrowerPlanNewDTO.getRefundDate().getTime());
                }

                // 逾期时间
                int overDueDay = RepaymentUtil.getOverdueDay(projectBorrowerPlanNewDTO.getRefundDate(), new Date());
                if (overDueDay > 0) {
                    projectRefundEventRequestDetail.setOverdueDay(overDueDay);
                    // 逾期金额 = 待还本金 + 待还利息
                    projectRefundEventRequestDetail.setOverdueAmount(projectBorrowerPlanNewDTO.getCapital().add(projectBorrowerPlanNewDTO.getInterest())
                            .subtract(projectBorrowerPlanNewDTO.getRefundedCapital()).subtract(projectBorrowerPlanNewDTO.getRefundedInterest()));
                }
                projectRefundEventRequestDetailList.add(projectRefundEventRequestDetail);

                // 累加金额信息
                projectBorrowerAmountSumDTO.setBorrowedAmount(projectBorrowerAmountSumDTO.getBorrowedAmount().add(projectBorrowerPlanNewDTO.getCapital()));
                projectBorrowerAmountSumDTO.setInterest(projectBorrowerAmountSumDTO.getInterest().add(projectBorrowerPlanNewDTO.getInterest()));
                projectBorrowerAmountSumDTO.setManagementFee(projectBorrowerAmountSumDTO.getManagementFee().add(projectBorrowerPlanNewDTO.getManagementFee()));
                projectBorrowerAmountSumDTO.setGuaranteeFee(projectBorrowerAmountSumDTO.getGuaranteeFee().add(projectBorrowerPlanNewDTO.getGuaranteeFee()));
                projectBorrowerAmountSumDTO.setPenaltyFee(projectBorrowerAmountSumDTO.getPenaltyFee().add(projectBorrowerPlanNewDTO.getPenaltyFee()));

                projectBorrowerAmountSumDTO.setRefundedCapital(projectBorrowerAmountSumDTO.getRefundedCapital().add(projectBorrowerPlanNewDTO.getRefundedCapital()));
                projectBorrowerAmountSumDTO.setRefundedInterest(projectBorrowerAmountSumDTO.getRefundedInterest().add(projectBorrowerPlanNewDTO.getRefundedInterest()));
                projectBorrowerAmountSumDTO.setRefundedManagementFee(projectBorrowerAmountSumDTO.getRefundedManagementFee().add(projectBorrowerPlanNewDTO.getRefundedManagementFee()));
                projectBorrowerAmountSumDTO.setRefundedGuaranteeFee(projectBorrowerAmountSumDTO.getRefundedGuaranteeFee().add(projectBorrowerPlanNewDTO.getRefundedGuaranteeFee()));
                projectBorrowerAmountSumDTO.setRefundedPenaltyFee(projectBorrowerAmountSumDTO.getRefundedPenaltyFee().add(projectBorrowerPlanNewDTO.getRefundedPenaltyFee()));
            });

            // 还款总金额
            BigDecimal totalAmount = projectBorrowerAmountSumDTO.getBorrowedAmount().add(projectBorrowerAmountSumDTO.getInterest())
                    .add(projectBorrowerAmountSumDTO.getManagementFee()).add(projectBorrowerAmountSumDTO.getGuaranteeFee())
                    .add(projectBorrowerAmountSumDTO.getPenaltyFee());

            // 已还款金额
            BigDecimal doneAmount = projectBorrowerAmountSumDTO.getRefundedCapital().add(projectBorrowerAmountSumDTO.getRefundedInterest())
                    .add(projectBorrowerAmountSumDTO.getRefundedManagementFee()).add(projectBorrowerAmountSumDTO.getRefundedGuaranteeFee())
                    .add(projectBorrowerAmountSumDTO.getRefundedPenaltyFee());

            // 剩余应还金额 = 还款总金额 - 已还金额
            BigDecimal lateAmount = totalAmount.subtract(doneAmount);

            // 借款金额，即本金
            BigDecimal borroweAmount = projectBorrowerAmountSumDTO.getBorrowedAmount();

            // 构建请求数据
            ProjectRefundEventRequest projectRefundEventRequest = new ProjectRefundEventRequest();
            projectRefundEventRequest.setUserId(dto.getBorrowerUserId());
            projectRefundEventRequest.setProjectId(dto.getProjectId());
            projectRefundEventRequest.setBorrowedAmount(borroweAmount);
            projectRefundEventRequest.setDoneAmount(doneAmount);
            projectRefundEventRequest.setLateAmount(lateAmount);
            projectRefundEventRequest.setUpdateTime(new Date().getTime());
            projectRefundEventRequest.setProjecterPayment(projectRefundEventRequestDetailList);
            RpcContext.getContext().asyncCall(new Runnable() {
                @Override
                public void run() {
                    //天秤回流
                    tianChengRefundEventService.refundSucceed(projectRefundEventRequest);
                }
            });
        } catch (Exception e) {
            log.error("sendTianCheng Exception,", e);
        }
    }


    private void masterRouteOnly() {
        if (!HintManagerHolder.isMasterRouteOnly()) {
            HintManagerHolder.clear();
            HintManager hintManager = HintManager.getInstance();
            hintManager.setMasterRouteOnly();
        }
    }
}
